<template v-slot:footer>
	<view>
		<uni-card 	
		    :title="task.taskName" 
		    mode="title" 
		    :is-shadow="true" 
		    thumbnail="https://img-cdn-qiniu.dcloud.net.cn/uniapp/images/muwu.jpg" 
		    :extra="task.taskMoney" 
		    note="88888"
		>
			{{task.taskContent}}
			<template v-slot:footer>
				<view class="footer-box">
					<button type="primary" @click="acceptTask">抢该任务</button>
				</view>
			</template>
		</uni-card>			
	</view>
</template>

<script>
	import uniCard from '@/components/uni-card/uni-card.vue'
	export default {
	    components: {uniCard},
		onLoad(options) {
			console.log(options)
			this.task=JSON.parse(options.data)
			console.log(this.task)
		},
		data(){
			return{
				task:{}
			}
		},
		methods:{
			async acceptTask(){
				//检查是否登陆
				if(this.$checkLogin("../taskDetail/taskDetail",1,JSON.stringify(this.task))){
					console.log('抢任务')
					//获取我的id
					var myId=uni.getStorageSync("user").userId
					//发起请求
					const res=await this.$myRequest({
						url:'/task/acceptTask',
						method:"PUT",
						data:{
							task:this.task,
							myId:myId
						},
						//抢失败提示且跳到主页
						failCallBack:()=>{
							setTimeout(()=>{
								uni.switchTab({
									url:'../../pages/index/index'
								})
							},1000)
						}						
					})
					//抢到任务提示且跳到主页
					uni.showToast({
						icon:"none",
						title:"恭喜你，抢到任务啦!"
					})
					setTimeout(()=>{
						uni.switchTab({
							url:'../../pages/index/index'
						})
					},1000)
				}	
			}
		}
	}
</script>

<style lang="scss">

</style>
